﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace IronWinter
{
    [Serializable]
    public class Ability
    {
        #region variables
        public static List<Ability> AbilityList = new List<Ability>();
        public const int DISPLAY_SIZE = 64;

        //Caster effects (might seperate into passive and active?)
        protected int m_castHealth, m_castArmor, m_castAtkPow, m_castArmorPen;
        protected float m_castMoveSpeed, m_castAtkMoveSpeed;

        //Target effects
        protected int m_targetHealth, m_targetArmor, m_targetAtkPow, m_targetArmorPen;
        protected float m_targetMoveSpeed, m_targetAtkMoveSpeed;

        protected float m_AOERadius, m_range;

        protected int m_damage, m_armorPen, m_duration;

        protected AnimatedSprite m_sprite;

        protected string m_name;

        public Texture2D texture;

        public String displayText = "Example ability description";
        public Rectangle clickBounds;
        private Vector2 displayLocation;

        public int value;

        #endregion

        public Ability(
            int castHealth, int castArmor, int castAtkPow, int castArmorPen,
            float castMoveSpeed, float castAtkMoveSpeed,

            //Target effects
            int targetHealth, int targetArmor, int targetAtkPow, int targetArmorPen,
            float targetMoveSpeed, float targetAtkMoveSpeed,

            float AOERadius, float range,

            int damage, int armorPen, int duration,

            string name,

            Texture2D tex,

            String display,
            Rectangle click,
            Vector2 displayLoc,
            int value)
        {
            m_castHealth = castHealth;
            m_castArmor = castArmor;
            m_castAtkPow = castAtkPow;
            m_castArmorPen = castArmorPen;
            m_castMoveSpeed = castMoveSpeed;
            m_castAtkMoveSpeed = castMoveSpeed;
            m_targetHealth = targetHealth;
            m_targetArmor = targetArmor;
            m_targetAtkPow = targetAtkPow;
            m_targetArmorPen = targetArmorPen;
            m_targetMoveSpeed = targetMoveSpeed;
            m_targetAtkMoveSpeed = targetAtkMoveSpeed;
            m_AOERadius = AOERadius;
            m_range = range;
            m_damage = damage;
            m_armorPen = armorPen;
            m_duration = duration;
            m_name = name;
            texture = tex;
            displayText = display;
            clickBounds = click;
            displayLocation = displayLoc;
        }

        public Ability(string name)
        {
            m_name = name;
        }

        // Damage and armor piercing, + damage to deal damage, - damage to heal
        public int damage
        {
            get { return m_damage; }
        }

        public int armorPen
        {
            get { return m_armorPen; }
        }

        // attributes of ability
        public float AOERadius
        {
            get { return m_AOERadius; }
        }

        public float range
        {
            get { return m_range; }
        }

        public int duration
        {
            get { return m_duration; }
        }

        public string name
        {
            get { return m_name; }
        }

        // (affects character attributes)

        public int maxHealth
        {
            get { return m_targetHealth; }
        }


        public int armor
        {
            get { return m_targetArmor; }

        }

        public int atkPow
        {
            get { return m_targetAtkPow; }
        }

        public int targetArmorPen
        {
            get { return m_targetArmorPen; }

        }

        public float moveSpeed
        {
            get { return m_targetMoveSpeed; }

        }

        public float atkMoveSpeed
        {
            get { return m_targetAtkMoveSpeed; }
        }

        public Vector2 Location
        {
            get { return displayLocation; }
            set
            {
                displayLocation = Location;
                clickBounds = new Rectangle((int)displayLocation.X, (int)displayLocation.Y, DISPLAY_SIZE, DISPLAY_SIZE);
            }
        }

        public void SetTex(Texture2D tex)
        {
            texture = tex;
            m_sprite = new AnimatedSprite(tex, 0, 0, DISPLAY_SIZE, DISPLAY_SIZE, 1);
            m_sprite.tint = Color.White;
        }



        public void activateAbility(ref List<Unit> list, int playX, int playY, int mouseX, int mouseY)
        {

        }

        public void Display(SpriteBatch sb, Rectangle destRect)
        {
            m_sprite.Draw(sb, destRect, Color.White);
        }

        public void Display(SpriteBatch sb, Vector2 location, float scale)
        {
            m_sprite.Draw(sb, location, scale);
        }

        public void Display(SpriteBatch sb, Vector2 location)
        {
            m_sprite.Draw(sb, (int)location.X, (int)location.Y);
        }

        public void Display(SpriteBatch sb)
        {
            m_sprite.Draw(sb, (int)displayLocation.X, (int)displayLocation.Y);
        }
    }
}
